<template>
  <div id="flight-order-detail">
    <nav aria-label="breadcrumb" role="navigation">
      <ol class="breadcrumb pb-0">
        <li class="breadcrumb-item">
          <router-link to="/flt/orders">机票订单</router-link>
        </li>
        <li class="breadcrumb-item active" aria-current="page">详情</li>
        <span class="ms-auto" @click.stop="back()">返回</span>
      </ol>
    </nav>
    <ul class="nav nav-tabs nav-bordered mb-3" id="myTab" role="tablist">
      <li class="nav-item">
        <a
          class="nav-link active"
          id="order-tab"
          data-bs-toggle="tab"
          href="#orderDetailTab"
          role="tab"
          aria-controls="home"
          aria-selected="true"
        >
          订单内容
        </a>
      </li>
      <li v-if="detail !== null && detail.subOrders.length > 0">
        <a
          class="nav-link"
          id="order-tab"
          data-bs-toggle="tab"
          href="#subOrderTab"
          role="tab"
          aria-controls="subOrder"
          aria-selected="true"
        >
          子订单
        </a>
      </li>
      <li class="nav-item">
        <a
          class="nav-link"
          id="pnr-tab"
          data-bs-toggle="tab"
          href="#pnrDetailTab"
          role="tab"
          aria-controls="pnr"
          aria-selected="false"
          >编码内容</a
        >
      </li>
      <li
        class="nav-item"
        v-if="detail !== null && detail.smsDetails.length > 0"
      >
        <a
          class="nav-link"
          id="sms-tab"
          data-bs-toggle="tab"
          href="#smsDetailTab"
          role="tab"
          aria-controls="sms"
          aria-selected="false"
          >短信({{ detail.smsDetails.length }})</a
        >
      </li>
      <li class="nav-item" v-if="detail !== null && detail.refunds.length > 0">
        <a
          class="nav-link"
          id="refund-tab"
          data-bs-toggle="tab"
          href="#refundTab"
          role="tab"
          aria-controls="refund"
          aria-selected="false"
          >退票({{ detail.refunds.length }})</a
        >
      </li>
      <li class="nav-item" v-if="detail !== null && detail.changes.length > 0">
        <a
          class="nav-link"
          id="change-tab"
          data-bs-toggle="tab"
          href="#changeTab"
          role="tab"
          aria-controls="change"
          aria-selected="false"
          >改签({{ detail.changes.length }})</a
        >
      </li>
      <li class="nav-item" v-if="detail !== null && detail.services.length > 0">
        <a
          class="nav-link"
          id="service-tab"
          data-bs-toggle="tab"
          href="#serviceTab"
          role="tab"
          aria-controls="service"
          aria-selected="false"
          >服务及保险({{ detail.services.length }})</a
        >
      </li>
      <li class="nav-item" v-if="detail !== null && deliveryMode === 1">
        <a
          class="nav-link"
          id="delivery-tab"
          data-bs-toggle="tab"
          href="#deliveryTab"
          role="tab"
          aria-controls="deliveries"
          aria-selected="false"
          >配送单({{ detail.deliveries.length }})</a
        >
      </li>
      <li class="nav-item" v-if="detail !== null && deliveryMode === 1">
        <a
          class="nav-link"
          id="comment-tab"
          data-bs-toggle="tab"
          href="#commentTab"
          role="tab"
          aria-controls="comment"
          aria-selected="false"
          >留言({{ commentCount }})</a
        >
      </li>
    </ul>
    <div class="tab-content" id="myTabContent">
      <div
        class="tab-pane fade show active"
        id="orderDetailTab"
        role="tabpanel"
        aria-labelledby="order-tab"
        v-if="detail !== null"
      >
        <div class="card">
          <div
            class="alert alert-warning alert-dismissible fade show"
            role="alert"
            v-if="
              detail.cancelRequest !== null && detail.cancelRequest.status === 0
            "
          >
            <button
              type="button"
              class="btn-close"
              data-bs-dismiss="alert"
              aria-label="Close"
            ></button>
            操作员
            <strong>{{ detail.cancelRequest.operator }}</strong>
            请求取消此订单， 因为:
            <strong>{{ detail.cancelRequest.reasonDesc }}</strong
            >, 可以吗？
            <button
              class="btn btn-sm btn-secondary"
              @click.stop="denyCancelRequest()"
            >
              不同意
            </button>
            <button
              class="me-5 btn btn-success"
              @click.stop="agreeCancelRequest()"
            >
              同意
            </button>
          </div>
          <div
            class="card-body py-0 px-0 accordion"
            id="accordion_order_summary"
          >
            <div class="accordion-item">
              <h2
                class="accordion-header mt-0"
                id="accordion_order_summary_heading_one"
              >
                <button
                  class="accordion-button collapsed bg-info text-white"
                  type="button"
                  data-bs-toggle="collapse"
                  data-bs-target="#accordion_order_summary_one"
                  aria-expanded="true"
                  aria-controls="collapseOne"
                >
                  订单概要
                </button>
              </h2>
              <div
                id="accordion_order_summary_one"
                class="accordion-collapse collapse show"
                data-bs-parent="#accordion_order_summary"
              >
                <div class="accordion-body">
                  <table class="table table-sm table-striped table-hover mb-0">
                    <thead>
                      <tr>
                        <th>订单号</th>
                        <th>外部订单号</th>
                        <th>编码</th>
                        <th>大编码</th>
                        <th>客户</th>
                        <th>国际?</th>

                        <th></th>
                        <th></th>
                        <th>出票时限</th>
                        <th>预订人</th>
                        <th>开票人</th>
                        <th>收款方式</th>
                        <th>供应商</th>
                        <th>付款方式</th>
                        <th>出票日期</th>
                        <th>收款状态</th>
                        <th>订单状态</th>
                        <th>使用情况</th>
                      </tr>
                    </thead>
                    <tbody>
                      <tr>
                        <td>{{ detail.orderNo }}</td>
                        <td>
                          {{ detail.externalOrderNo }}
                          <button v-if="detail.externalOrderNo"
                            type="button"
                            class="btn btn-primary btn-sm ms-3"
                            @click.stop="syncFlightOrderExternalOrderStatus($event.target)"
                          >
                            同步
                          </button>
                        </td>
                        <td>
                          {{ detail.pnrNo }}
                          <span class="text-danger" title="大客户代码">
                            <strong>{{ detail.keyCustomerNo }}</strong>
                          </span>
                        </td>
                        <td>
                          {{ detail.bigPnrNo }}
                        </td>
                        <td>
                          <template v-if="detail.customer !== null">
                            {{ detail.customer.name }}
                            <span class="text-danger small">{{
                              detail.customer.customerCode
                            }}</span>
                          </template>
                          <template v-else> 散客 </template>
                          /{{ detail.costCenter }} /{{ detail.projectName }}
                        </td>
                        <td>
                          <span
                            class="text-danger"
                            v-if="detail.intlTicket === 1"
                            >国际</span
                          >
                          <span v-else>国内</span>
                        </td>

                        <td></td>
                        <td></td>
                        <td>{{ detail.tktl }}</td>
                        <td>{{ detail.operator }}</td>
                        <td>{{ detail.ticketer }}</td>
                        <td>
                          {{ getPayTypeDesc(detail.payType) }}
                          /{{ detail.payRemark }}
                        </td>
                        <td>
                          <template v-if="detail.supplier !== null">
                            {{ detail.supplier.name }}
                          </template>
                        </td>
                        <td>
                          <template v-if="detail.paymentMethod !== null">
                            {{ detail.paymentMethod.name }}
                          </template>
                        </td>
                        <td>{{ detail.etdzDate }}</td>
                        <td>
                          <span
                            class="text-danger"
                            v-if="detail.payStatus === 0"
                            >未收款</span
                          >
                          <span
                            class="text-info"
                            v-else-if="detail.payStatus === 1"
                            >已收款</span
                          >
                          <span
                            class="text-primary"
                            v-else-if="detail.payStatus === 2"
                            >已销账</span
                          >
                        </td>
                        <td>
                          {{ getStatusDesc(detail.status) }}
                        </td>
                        <td>
                          {{ detail.showStatusDesc }}
                        </td>
                      </tr>
                    </tbody>
                  </table>
                  <table class="table table-sm table-striped table-hover mb-0">
                    <tbody>
                      <tr>
                        <td>联系人: {{ detail.linkman }}</td>
                        <td>联系电话: {{ detail.linkPhone }}</td>
                        <td>联系手机: {{ detail.linkMobile }}</td>
                        <td>联系Email: {{ detail.linkEmail }}</td>
                        <td>备注: {{ detail.remark }}</td>
                        <td>机票优惠代码: {{ detail.policyCode }}</td>
                        <td>
                          订单总金额: <strong>{{ detail.totalAmount }}</strong>
                        </td>
                        <td>
                          价格校验:
                          {{
                            showPriceCheckedStatus(detail.priceCheckedStatus)
                          }},
                          {{ detail.priceCheckedTime }}
                        </td>
                      </tr>
                    </tbody>
                  </table>
                </div>
              </div>
            </div>
          </div>

          <!-- 第三方系统开票操作区 -->
          <template
            v-if="isAdmin && detail.status !== 4 && detail.status !== 32"
          >
            <div class="card-body py-0 px-0 accordion" id="accordion_cz_ndc">
              <div class="accordion-item" v-show="false">
                <h2 class="accordion-header mt-0" id="cz_ndc_heading_one">
                  <button
                    class="accordion-button collapsed bg-info text-white"
                    type="button"
                    data-bs-toggle="collapse"
                    data-bs-target="#collapse_cz_ndc"
                    aria-expanded="true"
                    aria-controls="collapse_cz_ndc"
                  >
                    南航NDC操作区
                  </button>
                </h2>
                <div
                  id="collapse_cz_ndc"
                  class="accordion-collapse collapse"
                  aria-labelledby="cz_ndc_heading_one"
                  data-bs-parent="#accordion_cz_ndc"
                >
                  <div class="accordion-body">
                    <button
                      type="button"
                      class="btn btn-primary btn-sm ms-3"
                      @click="checkPrice()"
                    >
                      价格确认
                    </button>
                    <button
                      type="button"
                      class="btn btn-primary btn-sm ms-3"
                      @click.stop="payForExternalOrder()"
                      v-if="detail.externalOrderNo && detail.status !== 4"
                    >
                      支付
                    </button>

                    <button
                      type="button"
                      class="btn btn-primary btn-sm ms-3"
                      @click.stop="changeSupplierType(1)"
                    >
                      BSP供应商
                    </button>

                    <button
                      type="button"
                      class="btn btn-primary btn-sm ms-3"
                      @click.stop="changeSupplierType(4)"
                    >
                      CZ NDC供应商
                    </button>
                    <button
                      type="button"
                      class="btn btn-primary btn-sm ms-3"
                      @click.stop="issueTicket($event.target)"
                    >
                      一键出票
                    </button>
                    <button
                      type="button"
                      class="btn btn-primary btn-sm ms-3"
                      @click.stop="cancelClaim($event.target)"
                    >
                      取消认领
                    </button>
                  </div>
                </div>
              </div>
              <div class="accordion-item" v-if="tmsSuppliers.length > 0">
                <h2 class="accordion-header mt-0" id="cz_ndc_heading_two">
                  <button
                    class="accordion-button collapsed bg-info text-white"
                    type="button"
                    data-bs-toggle="collapse"
                    data-bs-target="#collapse_cz_ndc_2"
                    aria-expanded="true"
                    aria-controls="collapse_cz_ndc_2"
                  >
                    TMS平台操作区
                  </button>
                </h2>
                <div
                  id="collapse_cz_ndc_2"
                  class="accordion-collapse collapse show"
                  aria-labelledby="cz_ndc_heading_two"
                  data-bs-parent="#accordion_cz_ndc"
                >
                  <div class="accordion-body">
                    <div class="row mb-1">
                      <div class="col-2">
                        <select
                          class="form-select"
                          v-model.number="tmsSupplierId"
                        >
                          <option value="0">选择平台供应商</option>
                          <template v-for="info of tmsSuppliers">
                            <option
                              :value="info.id"
                              :key="`tms-supplier-` + info.id"
                            >
                              {{ info.name }}
                            </option>
                          </template>
                        </select>
                      </div>
                      <div class="col-1">
                        <button
                          type="button"
                          class="btn btn-success btn-sm ms-3"
                          @click="createEotmsFlightOrder($event.target)"
                        >
                          创建订单
                        </button>
                      </div>
                    </div>

                    <table class="table">
                      <thead>
                        <tr class="table-info">
                          <th>供应商名称</th>
                          <th>外部订单号</th>
                          <th>票面价</th>
                          <th>销售价</th>
                          <th>税</th>
                          <th>服务费</th>
                          <th>折扣</th>
                          <th>结算价</th>
                          <th>状态</th>
                          <th></th>
                        </tr>
                      </thead>
                      <tbody>
                        <tr
                          v-for="info of tmsExternalOrders"
                          :key="`tms_external_order_` + info.id"
                        >
                          <td>{{ info.supplierName }}</td>
                          <td>{{ info.externalOrderNo }}</td>
                          <td>{{ info.price }}</td>
                          <td>{{ info.parvalue }}</td>
                          <td>{{ info.tax }}</td>
                          <td>{{ info.serviceCharge }}</td>
                          <td>{{ info.discount }}</td>
                          <td>{{ info.cost }}</td>
                          <td>{{ info.orderStatus }}</td>
                          <td>
                            <button
                              type="button"
                              class="btn btn-primary btn-sm ms-3"
                              @click.stop="
                                syncEotmsFlightOrderStatus(
                                  info.id,
                                  $event.target
                                )
                              "
                            >
                              同步订单
                            </button>
                            <button
                              type="button"
                              class="btn btn-primary btn-sm ms-3"
                              @click.stop="
                                confirmEotmsFlightOrder(info.id, $event.target)
                              "
                            >
                              确认开票
                            </button>
                          </td>
                        </tr>
                      </tbody>
                    </table>
                  </div>
                </div>
              </div>
            </div>
          </template>

          <div class="card-body bg-info text-white py-1">航班信息</div>
          <table class="table table-striped table-hover table-sm mb-0">
            <thead>
              <tr>
                <th>出发</th>
                <th>到达</th>
                <th>出发日期</th>
                <th>航班号</th>
                <th>出发时间</th>
                <th>到达时间</th>
                <th>舱位</th>
              </tr>
            </thead>
            <tbody>
              <tr v-for="(info, index) in detail.flights" :key="index">
                <td>
                  <span class="text-success">{{ info.dport }}</span>
                  {{ info.dportName }}
                  {{ info.dterm }}
                </td>
                <td>
                  <span class="text-success">{{ info.aport }}</span>
                  {{ info.aportName }}
                  {{ info.aterm }}
                </td>
                <td>{{ info.ddate }}</td>
                <td>{{ info.flightNo }}</td>
                <td>
                  {{ info.dtime }}
                </td>
                <td>
                  <span
                    class="small text-info"
                    v-if="info.adate !== info.ddate"
                  >
                    {{ info.adate }}
                  </span>

                  {{ info.atime }}
                </td>
                <td>
                  {{ info.subclass }}
                  <span v-if="info.cabinClass !== null"
                    >({{ info.cabinClass }}舱)</span
                  >
                </td>
              </tr>
            </tbody>
          </table>
          <div class="card-body bg-info text-white py-1">乘机人信息</div>
          <order-passengers
            :detail="detail"
            @refresh="searchOrderDetail()"
          ></order-passengers>

          <template v-if="detail.tickets.length > 0">
            <div class="card-body bg-info text-white py-1">航班信息及票号</div>
            <table class="table table-striped table-hover table-sm mb-0">
              <thead>
                <tr>
                  <th class="text-end">姓名</th>
                  <th>票号</th>
                  <th>出发</th>
                  <th>到达</th>
                  <th>航班号</th>
                  <th>日期</th>
                  <th>时间</th>
                  <th>时间</th>
                  <th>舱位</th>
                  <th>状态</th>
                </tr>
              </thead>
              <tbody>
                <tr
                  v-for="(info, index) in detail.tickets"
                  :key="index"
                  :class="{
                    'text-decoration-line-through': info.ticketStatus === 2,
                  }"
                >
                  <td class="text-end">
                    {{ info.passengerName }}
                  </td>
                  <td>
                    {{ info.ticketNo }}
                  </td>
                  <td>{{ info.dport }} {{ info.dportName }}</td>
                  <td>{{ info.aport }} {{ info.aportName }}</td>
                  <td>{{ info.flightNo }}</td>
                  <td>{{ info.ddate }}</td>
                  <td>{{ info.dtime }}</td>
                  <td>{{ info.atime }}</td>
                  <td>{{ info.subclass }}</td>
                  <td>{{ showTicketStatus(info.ticketStatus) }}</td>
                </tr>
              </tbody>
            </table>
          </template>
          <div class="card-body bg-info text-white py-1">价格信息</div>
          <template v-if="priceEditing === 0">
            <div class="card-body py-0">
              <div
                class="d-flex flex-row justify-content-between"
                v-if="detail.adultCount > 0"
              >
                <div class="p-2 text-nowrap">成人</div>
                <div class="p-2 text-nowrap">
                  票面价: {{ adultPrice.price }}
                </div>
                <div class="p-2 text-nowrap">
                  销售价: {{ adultPrice.parValue }}
                </div>
                <div class="p-2 text-nowrap">税: {{ adultPrice.tax }}</div>
                <div class="p-2 text-nowrap">
                  保险费: {{ adultPrice.insurance }}
                </div>
                <div class="p-2 text-nowrap">
                  航司代理费: {{ adultPrice.commission }}
                </div>
                <div class="p-2 text-nowrap">
                  自定代理费: {{ adultPrice.commission2 }}
                </div>
                <div class="p-2 text-nowrap">
                  服务费: {{ adultPrice.serviceCharge }}
                </div>
                <div class="p-2 text-nowrap">
                  客户让利: {{ adultPrice.discount }}
                </div>
                <div class="p-2 text-nowrap">
                  人数: {{ adultPrice.ticketCount }}
                </div>
                <div class="p-2 text-nowrap">应收: {{ adultPrice.amount }}</div>
                <div class="p-2 text-nowrap">成本: {{ adultPrice.cost }}</div>
              </div>
              <div
                class="d-flex flex-row justify-content-between"
                v-if="detail.childCount > 0"
              >
                <div class="p-2 text-nowrap">儿童</div>
                <div class="p-2 text-nowrap">
                  票面价: {{ childPrice.price }}
                </div>
                <div class="p-2 text-nowrap">
                  销售价: {{ childPrice.parValue }}
                </div>
                <div class="p-2 text-nowrap">税: {{ childPrice.tax }}</div>
                <div class="p-2 text-nowrap">
                  保险费: {{ childPrice.insurance }}
                </div>
                <div class="p-2 text-nowrap">
                  航司代理费: {{ childPrice.commission }}
                </div>
                <div class="p-2 text-nowrap">
                  自定代理费: {{ childPrice.commission2 }}
                </div>
                <div class="p-2 text-nowrap">
                  服务费: {{ childPrice.serviceCharge }}
                </div>
                <div class="p-2 text-nowrap">
                  客户让利: {{ childPrice.discount }}
                </div>
                <div class="p-2 text-nowrap">
                  人数: {{ childPrice.ticketCount }}
                </div>
                <div class="p-2 text-nowrap">应收: {{ childPrice.amount }}</div>
                <div class="p-2 text-nowrap">成本: {{ childPrice.cost }}</div>
              </div>
              <div
                class="d-flex flex-row justify-content-between"
                v-if="detail.infantCount > 0"
              >
                <div class="p-2 text-nowrap">婴儿</div>
                <div class="p-2 text-nowrap">
                  票面价: {{ infantPrice.price }}
                </div>
                <div class="p-2 text-nowrap">
                  销售价: {{ infantPrice.parValue }}
                </div>
                <div class="p-2 text-nowrap">税: {{ infantPrice.tax }}</div>
                <div class="p-2 text-nowrap">
                  保险费: {{ infantPrice.insurance }}
                </div>
                <div class="p-2 text-nowrap">
                  航司代理费: {{ infantPrice.commission }}
                </div>
                <div class="p-2 text-nowrap">
                  自定代理费: {{ infantPrice.commission2 }}
                </div>
                <div class="p-2 text-nowrap">
                  服务费: {{ infantPrice.serviceCharge }}
                </div>
                <div class="p-2 text-nowrap">
                  客户让利: {{ infantPrice.discount }}
                </div>
                <div class="p-2 text-nowrap">
                  人数: {{ infantPrice.ticketCount }}
                </div>
                <div class="p-2 text-nowrap">
                  应收: {{ infantPrice.amount }}
                </div>
                <div class="p-2 text-nowrap">成本: {{ infantPrice.cost }}</div>
              </div>
              <div class="d-flex flex-row justify-content-between">
                <div class="p-2 text-nowrap text-success">
                  小计: {{ detail.subTotal }}
                </div>
                <div class="p-2 text-nowrap text-success">
                  成本: {{ detail.totalCost }}
                </div>
                <div class="p-2 text-nowrap text-success">
                  利润: {{ detail.profit }}
                </div>
              </div>
            </div>
          </template>
          <template v-else>
            <my-price-input
              psgTypeName="成人"
              key="adultPriceInput"
              v-bind.sync="adultPrice"
              v-if="detail.adultCount > 0"
            ></my-price-input>

            <my-price-input
              psgTypeName="儿童"
              key="childPriceInput"
              v-bind.sync="childPrice"
              v-if="detail.childCount > 0"
            ></my-price-input>

            <my-price-input
              psgTypeName="婴儿"
              key="infantPriceInput"
              v-bind.sync="infantPrice"
              v-if="detail.infantCount > 0"
            ></my-price-input>

            <table class="table table-sm">
              <tbody>
                <tr>
                  <td class="text-center">
                    <button
                      class="btn btn-primary"
                      @click.stop="saveNewPrice()"
                    >
                      保存
                    </button>
                    <button
                      class="btn btn-secondary ms-3"
                      @click.stop="cancelEditPrice()"
                    >
                      取消
                    </button>
                  </td>
                </tr>
              </tbody>
            </table>
          </template>

          <table
            class="table table-striped table-hover table-sm"
            v-if="deliveryMode === 0"
          >
            <thead>
              <tr>
                <th></th>
                <th>派送日期</th>
                <th>收件人</th>
                <th>联系电话</th>
                <th>邮寄地址</th>
                <th>备注</th>
                <th>状态</th>
              </tr>
            </thead>
            <tbody>
              <tr>
                <td>{{ detail.deliveryNoteNo }}</td>
                <td>{{ detail.deliveryDate }}</td>
                <td>{{ detail.itineraryRecipient }}</td>
                <td>{{ detail.itineraryRecipientMobile }}</td>
                <td>{{ detail.itineraryMailingAddress }}</td>
                <td>{{ detail.itineraryMailingMemo }}</td>
                <td>
                  <template v-if="detail.itineraryMailingStatus === 0">
                    未邮寄
                  </template>
                  <template v-else-if="detail.itineraryMailingStatus === 1">
                    已邮寄
                  </template>
                </td>
              </tr>
            </tbody>
          </table>

          <div
            class="card-body bg-info text-white py-1"
            v-if="detail.attachments.length > 0"
          >
            附件
          </div>
          <table
            class="table table-striped table-sm table-hover"
            v-if="detail.attachments.length > 0"
          >
            <thead>
              <tr>
                <th>文件名</th>
                <th>类型</th>
                <th>尺寸</th>
                <th>描述</th>
                <th></th>
              </tr>
            </thead>
            <tbody>
              <tr
                v-for="(info, index) of detail.attachments"
                :key="`attachment_` + index"
              >
                <td>{{ info.fileName }}</td>
                <td>{{ info.contentType }}</td>
                <td>{{ info.fileSize }}</td>
                <td>
                  {{ info.description }}
                </td>
                <td>
                  <template v-if="info.contentType.indexOf('image') >= 0">
                    <img
                      :src="info.url"
                      style="width: 2em; height: 2em"
                      @click.stop="viewImg(info.url)"
                    />
                  </template>
                  <a :href="info.url">下载</a>
                </td>
              </tr>
            </tbody>
          </table>

          <div class="card-body">
            <template
              v-if="
                !(
                  detail.status === 4 ||
                  detail.status === 16 ||
                  detail.status === 32
                )
              "
            >
              <button
                class="btn btn-danger btn-sm ms-3"
                @click.stop="cancelOrder()"
              >
                取消订单
              </button>
            </template>

            <template v-if="detail.passengers.length > 0">
              <button
                class="btn btn-primary btn-sm ms-3"
                :disabled="btnDisabled"
                @click.stop="submitOrder()"
                v-if="detail.status === 0"
              >
                申请开票
              </button>
              <button
                class="btn btn-success btn-sm ms-3"
                @click.stop="approveOrder()"
                v-if="detail.status === 1"
              >
                审批通过
              </button>
              <button
                class="btn btn-success btn-sm ms-3"
                :disabled="btnDisabled"
                @click.stop="toTicketOrder()"
                v-if="detail.status === 2"
              >
                我来开票
              </button>
              <button
                class="btn btn-primary btn-sm ms-3"
                @click.stop="fillTicketNo()"
                v-if="detail.status === 8 || detail.status === 16"
              >
                填写票号
              </button>
              <button
                class="btn btn-danger btn-sm ms-3"
                @click.stop="finishOrder()"
                v-if="detail.status === 16"
              >
                订单完成
              </button>
              <button
                class="btn btn-danger btn-sm ms-3"
                @click.stop="rollbackStatus()"
                v-if="
                  isAdmin &&
                  (detail.status === 16 || detail.status === 32) &&
                  detail.payStatus !== 2
                "
              >
                回滚
              </button>
              <button
                class="btn btn-warning btn-sm ms-3"
                @click.stop="sendApprovalSms()"
                v-if="detail.status === 0"
              >
                发短信
              </button>

              <button
                class="btn btn-secondary btn-sm ms-3"
                @click.stop="editPrice()"
                v-if="
                  detail.status === 0 ||
                  detail.status === 2 ||
                  detail.status === 8 ||
                  detail.status === 16
                "
              >
                修改价格
              </button>

              <div
                class="btn-group ms-3"
                v-if="
                  detail.status === 0 ||
                  detail.status === 2 ||
                  detail.status === 8 ||
                  detail.status === 16
                "
              >
                <button
                  type="button"
                  class="btn btn-secondary btn-sm dropdown-toggle"
                  data-bs-toggle="dropdown"
                  aria-haspopup="true"
                  aria-expanded="false"
                >
                  修改...
                </button>
                <div class="dropdown-menu">
                  <a
                    @click.stop="editCustomer()"
                    href="javascript:void(0);"
                    class="dropdown-item"
                  >
                    更改客户
                  </a>
                  <a
                    @click.stop="editTicketSupplier()"
                    href="javascript:void(0);"
                    class="dropdown-item"
                  >
                    更改供应商
                  </a>
                  <a
                    @click.stop="editIntlTicket()"
                    href="javascript:void(0);"
                    class="dropdown-item"
                  >
                    更改订单类型
                  </a>
                  <a
                    @click.stop="editPnrNo()"
                    href="javascript:void(0);"
                    class="dropdown-item"
                  >
                    更改编码
                  </a>
                  <a
                    @click.stop="editKeyCustomerNo()"
                    href="javascript:void(0);"
                    class="dropdown-item"
                  >
                    更改大客户码
                  </a>
                  <a
                    @click.stop="editRemark()"
                    href="javascript:void(0);"
                    class="dropdown-item"
                  >
                    修改备注
                  </a>
                  <a
                    @click.stop="editLinkman()"
                    href="javascript:void(0);"
                    class="dropdown-item"
                  >
                    联系人
                  </a>
                  <a
                    @click.stop="editLinkPhone()"
                    href="javascript:void(0);"
                    class="dropdown-item"
                  >
                    联系电话
                  </a>
                  <a
                    @click.stop="editLinkMobile()"
                    href="javascript:void(0);"
                    class="dropdown-item"
                  >
                    联系手机
                  </a>
                  <a
                    @click.stop="editLinkEmail()"
                    href="javascript:void(0);"
                    class="dropdown-item"
                  >
                    联系Email
                  </a>
                  <a
                    @click.stop="changeTicketer()"
                    href="javascript:void(0);"
                    class="dropdown-item"
                    v-if="isAdmin"
                  >
                    出票人
                  </a>
                </div>
              </div>
              <template v-if="detail.status === 32">
                <button
                  class="btn btn-success btn-sm me-2 float-end"
                  @click.stop="outputBillInfo()"
                  v-if="false"
                >
                  输出为账单
                </button>
              </template>

              <div class="btn-group ms-5" v-if="detail.status !== 4">
                <button
                  type="button"
                  class="btn btn-primary btn-sm dropdown-toggle"
                  data-bs-toggle="dropdown"
                  aria-haspopup="true"
                  aria-expanded="false"
                >
                  增加服务
                </button>
                <div class="dropdown-menu">
                  <a
                    @click.stop="addInsurance()"
                    href="javascript:void(0);"
                    class="dropdown-item"
                  >
                    增加保险
                  </a>
                  <a
                    @click.stop="addExtraService()"
                    href="javascript:void(0);"
                    class="dropdown-item"
                  >
                    增加其它服务
                  </a>
                  <a
                    @click.stop="addExtraService2()"
                    href="javascript:void(0);"
                    class="dropdown-item"
                  >
                    增加机场服务
                  </a>
                </div>
              </div>

              <button
                class="btn btn-warning btn-sm ms-3 me-2"
                @click.stop="exportGroupPassengerFile('HO')"
                v-if="detail.status !== 4"
              >
                导出HO团客格式
              </button>
              <button
                class="btn btn-warning btn-sm ms-3 me-2"
                @click.stop="exportGroupPassengerFile('MU')"
                v-if="detail.status !== 4"
              >
                导出MU团客格式
              </button>
              <button
                class="btn btn-sm btn-secondary me-2 float-end"
                @click.stop="printItinerary()"
                v-if="detail.status !== 4"
              >
                行程单
              </button>
              <router-link
                :to="`/flt/order/` + detail.id + `/history`"
                class="btn btn-info btn-sm float-end me-2"
              >
                操作记录
              </router-link>
            </template>
            <template v-else>
              <button
                class="btn btn-primary ms-3 me-2"
                @click.stop="uploadPassengers()"
              >
                上传乘机人
              </button>
            </template>

            <button
              class="btn btn-secondary btn-sm ms-3 me-2"
              @click.stop="editAttachment2()"
              v-if="detail.status !== 4"
            >
              添加附件
            </button>
          </div>
        </div>
      </div>
      <div
        class="tab-pane fade"
        id="subOrderTab"
        role="tabpanel"
        v-if="detail !== null && detail.subOrders.length > 0"
      >
        <table class="table table-responsive">
          <thead>
            <tr class="bg-info bg-gradient">
              <td>类型</td>
              <td>订单号</td>
              <td>状态</td>
              <td>金额</td>
              <td></td>
            </tr>
          </thead>
          <tbody>
            <tr
              v-for="subOrder of detail.subOrders"
              :key="`sub_order_` + subOrder.id"
            >
              <td>{{ showOrderType(subOrder.orderType) }}</td>
              <td>{{ subOrder.orderNo }}</td>
              <td>{{ subOrder.orderStatus }}</td>
              <td>{{ subOrder.total }}</td>
              <td>
                <router-link :to="`/vas/order/` + subOrder.id"
                  >查看</router-link
                >
              </td>
            </tr>
          </tbody>
        </table>
      </div>
      <div
        class="tab-pane fade"
        id="pnrDetailTab"
        role="tabpanel"
        aria-labelledby="pnr-tab"
        v-if="detail !== null"
      >
        <div
          class="card-block bg-faded"
          v-if="detail.pnrDetail != null"
          style="padding: 0"
        >
          <div v-html="'<pre>' + detail.pnrDetail + '</pre>'"></div>
        </div>
      </div>
      <div
        class="tab-pane fade"
        id="smsDetailTab"
        role="tabpanel"
        aria-labelledby="sms-tab"
        v-if="detail !== null && detail.smsDetails.length > 0"
      >
        <sms-detail-list :dataList="detail.smsDetails"></sms-detail-list>
      </div>
      <div
        class="tab-pane fade"
        id="refundTab"
        role="tabpanel"
        aria-labelledby="refund-tab"
        v-if="detail !== null && detail.refunds.length > 0"
      >
        <flight-refund-list :dataList="detail.refunds"></flight-refund-list>
      </div>
      <div
        class="tab-pane fade"
        id="changeTab"
        role="tabpanel"
        aria-labelledby="change-tab"
        v-if="detail !== null && detail.changes.length > 0"
      >
        <flight-change-list :dataList="detail.changes"></flight-change-list>
      </div>
      <div
        class="tab-pane fade"
        id="serviceTab"
        role="tabpanel"
        aria-labelledby="service-tab"
        v-if="detail !== null && detail.services.length > 0"
      >
        <vas-order-list :dataList="detail.services"></vas-order-list>
      </div>
      <div
        class="tab-pane fade"
        id="deliveryTab"
        role="tabpanel"
        aria-labelledby="delivery-tab"
        v-if="detail !== null && deliveryMode === 1"
      >
        <delivery-list :dataList="detail.deliveries"></delivery-list>
        <div class="card">
          <div class="card-body">
            <button
              class="btn btn-primary"
              @click.stop="prepareDelivery()"
              v-if="detail.status !== 4"
            >
              配送
            </button>
          </div>
        </div>
      </div>
      <div
        class="tab-pane fade"
        id="commentTab"
        role="tabpanel"
        aria-labelledby="comment-tab"
        v-if="detail !== null"
      >
        <order-comment
          :orderType="1000"
          :orderId="this.id"
          :commentCount.sync="commentCount"
        ></order-comment>
      </div>
    </div>

    <my-modal-prompt ref="modalPrompt" :nullable="modalNullable">
      <span slot="title">{{ modalTitle }}</span>
    </my-modal-prompt>
    <my-modal-update-customer ref="updateCustomerModal">
    </my-modal-update-customer>
    <my-modal-supplier-update ref="updateSupplierModal">
    </my-modal-supplier-update>
    <my-modal-fill-ticket-no ref="fillTicketNoModal"></my-modal-fill-ticket-no>
    <my-modal-op2-update ref="updateOp2Modal">
      <span slot="title">{{ modalTitle }}</span>
      <span slot="title2">{{ modalTitle2 }}</span>
    </my-modal-op2-update>
    <my-modal-change-date ref="updateDateModal">
      <span slot="title">{{ modalTitle }}</span>
    </my-modal-change-date>
    <my-modal-sms ref="modalSms" :nullable="modalNullable">
      <span slot="title">{{ modalTitle }}</span>
    </my-modal-sms>
    <my-modal-viewer ref="modalViewer"></my-modal-viewer>

    <my-modal-excel-upload ref="modalUploadExcel" :hideCustomer="true">
      用Excel导入乘机人信息
      <template v-slot:excelFormatDesc>
        Excel格式说明: 姓名，证件号，手机号，证件类型，乘机人类型
      </template>
    </my-modal-excel-upload>
    <my-modal-upload-attachment
      ref="modalUploadFile"
      :orderType="orderType"
      :orderId="id"
    >
    </my-modal-upload-attachment>

    <my-modal-flight-offer-price ref="modalOfferPrice">
    </my-modal-flight-offer-price>
    <my-modal-update-passenger ref="updatePassengerModal">
    </my-modal-update-passenger>
    <my-modal-change-ticket ref="changeTicketModal" id="changeModal">
    </my-modal-change-ticket>
    <my-modal-refund-ticket-multi id="refundModal" ref="multiRefundTicketModal">
    </my-modal-refund-ticket-multi>
  </div>
</template>

<script>
import $ from "jquery";
import {
  APP_FLIGHT_PATH,
  SUPPLIER_FLIGHT,
  ORDER_TYPE_FLIGHT,
} from "@/common/const.js";
import {
  uploadFlightOrderPassengers,
  updateFlightOrderPrice,
  updateFlightOrderRemark,
  updateFlightOrderSupplier,
  updateFlightOrderTicket,
  cancelFlightOrder,
  submitFlightOrder,
  toticketFlightOrder,
  agreeFlightOrderCancelRequest,
  denyFlightOrderCancelRequest,
  updateFlightOrderPnr,
  updateFlightOrderKeyCustomerNo,
  updateFlightOrderProperty,
  updateFlightOrderCustomer,
  finishFlightOrder,
  updateFlightOrderIntl,
  updateFlightOrderTicketer,
  confirmFlightOrderPrice,
  syncEotmsFlightOrderStatus,
  confirmEotmsFlightOrder,
  payForExternalOrder,
  issueFlightOrderTicket,
  changeFlightOrderSupplierType,
  cancelClaimFlightOrder,
  createEotmsFlightOrder,
  searchEotmsFlightOrders,
} from "@/api/flight.js";
import {
  searchFlightOrderDetail,
  outputFlightOrder2Bill,
  searchFlightOrderDetailByOrderNo,
  convertPriceInfo,
  searchTmsSuppliers,
  syncFlightOrderExternalOrderStatus
} from "@/api/flight.js";
import { approveFlightOrder } from "@/api/flight.js";
import {
  showFlightOrderStatus,
  showPayType,
  showOrderTypeDesc,
  showTicketStatus,
  showApprovalStatus,
  showViolationStatus,
  showPriceCheckedStatus,
} from "@/common/common.js";
import { sendFlightOrderApprovalSms } from "@/api/sms.js";

import { rollbackFlightOrderStatus } from "@/api/admin.js";

import PriceInfo from "@/common/PriceInfo.js";
import MyPriceInput from "@/components/flight-price-input.vue";

import MyModalPrompt from "@/components/modal/my-modal-prompt.vue";
import MyModalSupplierUpdate from "@/components/modal/my-modal-supplier-update-v2.vue";
import MyModalFillTicketNo from "@/components/modal/my-modal-fill-ticketno.vue";
import MyModalUpdateCustomer from "@/components/modal/my-modal-customer-update.vue";
import MyModalOp2Update from "@/components/modal/my-modal-op1-update.vue";
import MyModalChangeDate from "@/components/modal/my-modal-change-date.vue";
import MyModalSms from "@/components/modal/my-modal-sms.vue";
import MyModalFlightOfferPrice from "@/components/modal/my-modal-flight-offer-price.vue";
import MyModalViewer from "@/components/modal/my-modal-viewer.vue";
import MyModalUploadAttachment from "@/components/modal/my-modal-upload-attatchment.vue";

import MyModalUpdatePassenger from "@/components/modal/my-modal-update-passenger.vue";
import MyModalChangeTicket from "@/components/modal/my-modal-change-ticket-multi.vue";
import MyModalRefundTicketMulti from "@/components/modal/my-modal-refund-ticket-multi.vue";

import FlightRefundList from "@/components/list/flight-order-refund-list.vue";
import FlightChangeList from "@/components/list/flight-order-change-list.vue";
import VasOrderList from "@/components/list/vas-order-list.vue";
import SmsDetailList from "@/components/list/sms-detail-list.vue";
import DeliveryList from "@/components/list/delivery-list.vue";
import OrderComment from "@/components/comment/order-comment.vue";
import OrderAttachments from "@/components/attachment/order-attachments.vue";
import OrderPassengers from "./flight-order-detail-passengers.vue";
import OrderFunctions from "./flight-order-detail-buttons.vue";

import MyModalExcelUpload from "@/components/modal/my-modal-excel-upload-passengers.vue";

export default {
  components: {
    MyPriceInput,
    MyModalPrompt,
    MyModalUpdateCustomer,
    MyModalSupplierUpdate,
    MyModalFillTicketNo,
    MyModalOp2Update,
    MyModalChangeDate,
    MyModalSms,
    MyModalViewer,
    MyModalExcelUpload,
    MyModalFlightOfferPrice,
    MyModalUpdatePassenger,
    MyModalChangeTicket,
    MyModalRefundTicketMulti,
    MyModalUploadAttachment,

    SmsDetailList,
    DeliveryList,
    FlightRefundList,
    FlightChangeList,
    VasOrderList,
    OrderComment,
    OrderAttachments,
    OrderPassengers,
    OrderFunctions,
  },
  data() {
    return {
      detail: null,
      id: 0,
      orderNo: "",

      adultPrice: new PriceInfo(),
      childPrice: new PriceInfo(),
      infantPrice: new PriceInfo(),

      priceEditing: 0,

      remark: "",

      commentCount: 0, //留言数量

      extras: [],
      modalTitle: "",
      modalTitle2: "",
      modalNullable: false,

      btnDisabled: false,
      attachments: [],

      priceOfferInfo: null,
      offerItemIds: [],
      tmsSuppliers: [],
      tmsSupplierId: 0,
      tmsExternalOrders: [],
    };
  },
  computed: {
    isAdmin() {
      return this.$store.getters.isAdmin;
    },
    customerId: function () {
      if (
        this.detail === null ||
        this.detail.customer === undefined ||
        this.detail.customer === null
      ) {
        return 0;
      } else {
        return this.detail.customer.id;
      }
    },
    psgCount: function () {
      if (this.detail !== null) {
        this.priceInfo.ticketCount = this.detail.passengers.length;
        return this.priceInfo.ticketCount;
      } else {
        this.priceInfo.ticketCount = 1;
        return 1;
      }
    },
    supplierId: function () {
      if (this.detail === null || this.detail.supplier === null) {
        return 0;
      } else {
        return this.detail.supplier.id;
      }
    },
    bspTicketingType: function () {
      if (this.detail === null || this.detail.supplier === null) {
        return 0;
      } else {
        return this.detail.supplier.isBsp;
      }
    },
    payMethodId: function () {
      if (this.detail === null || this.detail.paymentMethod === null) {
        return 0;
      } else {
        return this.detail.paymentMethod.id;
      }
    },
    deliveryMode: function () {
      //配送模式 0-原有的，1-新的
      if (this.detail.itineraryType === 0) {
        return 1;
      } else if (this.detail.deliveries.length === 0) {
        return 0;
      } else {
        return 1;
      }
    },
    orderType: function () {
      return ORDER_TYPE_FLIGHT;
    },
  },
  mounted: function () {
    this.id = parseInt(this.$route.params.id);
    if (this.id === 0) {
      this.orderNo = this.$route.query.orderNo;
    }
    this.searchOrderDetail();
    this.searchTmsSuppliers();
    this.searchEotmsFlightOrders();
  },
  methods: {
    back: function () {
      this.$router.go(-1);
    },
    showErrMsg: function (msg, msgType) {
      this.$store.dispatch("showAlertMsg", {
        errMsg: msg,
        errMsgType: msgType,
      });
    },
    showLoading: function (loadingText) {
      this.$store.commit("showLoading", {
        loading: true,
        loadingText: loadingText,
      });
    },
    hideLoading: function () {
      this.$store.commit("showLoading", { loading: false });
    },
    searchOrderDetail: function () {
      if (this.id > 0) {
        searchFlightOrderDetail(this.id, (v) => {
          this.setDetail(v);
        });
      } else {
        searchFlightOrderDetailByOrderNo(this.orderNo, (v) => {
          this.setDetail(v);
        });
      }
    },
    setDetail: function (v) {
      if (v.errcode === 0) {
        this.detail = v;
        this.id = this.detail.id;
        this.setAdultPrice();
      } else {
        this.showErrMsg(v.errcode + ": " + v.errmsg, "danger");
      }
    },
    getStatusDesc: function (status) {
      return showFlightOrderStatus(status);
    },
    getPayTypeDesc: function (payType) {
      return showPayType(payType);
    },
    showPriceCheckedStatus: function (status) {
      return showPriceCheckedStatus(status);
    },
    setAdultPrice: function () {
      convertPriceInfo(this.detail.prices, 0, this.adultPrice);
      convertPriceInfo(this.detail.prices, 1, this.childPrice);
      convertPriceInfo(this.detail.prices, 2, this.infantPrice);

      this.adultPrice.ticketCount = this.detail.adultCount;
      this.childPrice.ticketCount = this.detail.childCount;
      this.infantPrice.ticketCount = this.detail.infantCount;
    },
    editPrice: function () {
      this.priceEditing = 1;
    },
    cancelEditPrice: function () {
      this.priceEditing = 0;
    },
    saveNewPrice: function () {
      const params = {
        adultCount: this.detail.adultCount,
        childCount: this.detail.childCount,
        infantCount: this.detail.infantCount,
        adultPrice: this.adultPrice,
        childPrice: this.childPrice,
        infantPrice: this.infantPrice,
      };

      const str = JSON.stringify(params);

      updateFlightOrderPrice(this.id, str, (jsonResult) => {
        this.commonShowMessage(jsonResult);
        if (jsonResult.status === "OK") {
          this.priceEditing = 0;
          this.showErrMsg("操作成功");
        } else {
          this.showErrMsg("操作失败", "danger");
        }
      });
    },
    editRemark: function () {
      this.modalTitle = "请输入新的备注：";
      this.modalNullable = false;
      this.$refs.modalPrompt
        .modal()
        .then((remark) => {
          updateFlightOrderRemark(this.id, { remark: remark }, (v) =>
            this.commonShowMessage(v)
          );
        })
        .catch((ex) => {});
    },
    editLinkman: function () {
      this.modalTitle = "修改联系人：";
      this.modalNullable = false;
      this.$refs.modalPrompt
        .modal(this.detail.linkman)
        .then((remark) => {
          updateFlightOrderProperty(
            this.id,
            { name: "linkman", value: remark },
            (v) => this.commonShowMessage(v)
          );
        })
        .catch((ex) => {});
    },
    editLinkPhone: function () {
      this.modalTitle = "修改联系电话：";
      this.modalNullable = false;
      this.$refs.modalPrompt
        .modal(this.detail.linkPhone)
        .then((remark) => {
          updateFlightOrderProperty(
            this.id,
            { name: "linkPhone", value: remark },
            (v) => this.commonShowMessage(v)
          );
        })
        .catch((ex) => {});
    },
    editLinkMobile: function () {
      this.modalTitle = "修改联系手机：";
      this.modalNullable = false;
      this.$refs.modalPrompt
        .modal(this.detail.linkMobile)
        .then((remark) => {
          updateFlightOrderProperty(
            this.id,
            { name: "linkMobile", value: remark },
            (v) => this.commonShowMessage(v)
          );
        })
        .catch((ex) => {});
    },
    editLinkEmail: function () {
      this.modalTitle = "修改联系email：";
      this.modalNullable = false;
      this.$refs.modalPrompt
        .modal(this.detail.linkEmail)
        .then((remark) => {
          updateFlightOrderProperty(
            this.id,
            { name: "linkEmail", value: remark },
            (v) => this.commonShowMessage(v)
          );
        })
        .catch((ex) => {});
    },
    cancelOrder: function () {
      this.modalTitle = "请输入取消订单的理由：";
      this.modalNullable = false;
      this.$refs.modalPrompt
        .modal()
        .then((remark) => {
          cancelFlightOrder(this.id, { reasonDesc: remark }, (v) =>
            this.commonShowMessage(v)
          );
        })
        .catch((ex) => {});
    },
    checkPrice: function () {
      this.$refs.modalOfferPrice
        .modal(this.id)
        .then((params) => {
          confirmFlightOrderPrice(this.id, params, (v) =>
            this.commonShowMessage(v)
          );
        })
        .catch((ex) => {});
    },
    submitOrder: function () {
      this.$refs.updateSupplierModal
        .modal(
          this.supplierId,
          this.payMethodId,
          SUPPLIER_FLIGHT,
          this.bspTicketingType
        )
        .then((info) => {
          const params = {
            supplierId: info.supplierId,
            paymentMethodId: info.paymentMethodId,
            autoTicketing: info.autoTicketing,
            price: info.price,
          };
          updateFlightOrderSupplier(this.id, params, (v) => {
            if (v.status === "OK") {
              this.doSubmitOrder();
            } else {
              this.showErrMsg("失败：" + v.errmsg, "danger");
            }
          });
        })
        .catch((ex) => {});
    },
    doSubmitOrder: function () {
      this.btnDisabled = true;
      this.showLoading("处理中");
      submitFlightOrder(
        this.id,
        (v) => this.commonShowMessage(v),
        () => {
          this.btnDisabled = false;
          this.hideLoading();
        }
      );
    },
    approveOrder: function () {
      this.showLoading("处理中");
      approveFlightOrder(
        this.id,
        (v) => this.commonShowMessage(v),
        () => this.hideLoading()
      );
    },
    toTicketOrder: function () {
      this.btnDisabled = true;
      this.showLoading("处理中");
      toticketFlightOrder(
        this.id,
        (v) => {
          this.commonShowMessage(v);
        },
        () => {
          this.btnDisabled = false;
          this.hideLoading();
        }
      );
    },
    finishOrder: function () {
      // 此处允许修改出票日期
      this.modalTitle = "请输入出票日期（默认当天)：";
      this.$refs.updateDateModal
        .modal()
        .then((remark) => {
          finishFlightOrder(this.id, { etdzDate: remark }, (v) =>
            this.commonShowMessage(v)
          );
        })
        .catch((ex) => {});
    },
    outputBillInfo: function () {
      outputFlightOrder2Bill(this.id, (v) => this.commonShowMessage(v));
    },
    editCustomer: function () {
      this.$refs.updateCustomerModal
        .modal(this.customerId)
        .then((info) => {
          updateFlightOrderCustomer(
            this.id,
            {
              customerId: info.customerId,
              costCenter: info.costCenter,
              projectName: info.projectName,
            },
            (v) => this.commonShowMessage(v)
          );
        })
        .catch((ex) => {});
    },
    editIntlTicket: function () {
      const intlTicket = this.detail.intlTicket;
      let newIntlTicket = 0;
      if (intlTicket === 0) {
        this.modalTitle = "确定更改为国际机票订单？";
        newIntlTicket = 1;
      } else {
        this.modalTitle = "确定更改为国内机票订单？";
        newIntlTicket = 0;
      }

      this.$refs.modalPrompt
        .modal("YesOrNo")
        .then((remark) => {
          updateFlightOrderIntl(this.id, { intlTicket: newIntlTicket }, (v) =>
            this.commonShowMessage(v)
          );
        })
        .catch((ex) => {});
    },
    editTicketSupplier: function () {
      this.$refs.updateSupplierModal
        .modal(
          this.supplierId,
          this.payMethodId,
          SUPPLIER_FLIGHT,
          this.bspTicketingType
        )
        .then((info) => {
          const params = {
            supplierId: info.supplierId,
            paymentMethodId: info.paymentMethodId,
            autoTicketing: info.autoTicketing,
            price: info.price,
          };
          updateFlightOrderSupplier(this.id, params, (v) => {
            this.commonShowMessage(v);
          });
        })
        .catch((ex) => {});
    },
    editPnrNo: function () {
      this.modalTitle = "修改编码：";
      this.modalNullable = false;
      this.$refs.modalPrompt
        .modal()
        .then((pnrNo) => {
          updateFlightOrderPnr(this.id, { pnrNo: pnrNo }, (v) =>
            this.commonShowMessage(v)
          );
        })
        .catch((ex) => {});
    },
    editKeyCustomerNo: function () {
      this.modalTitle = "修改大客户码：";
      this.modalNullable = false;
      this.$refs.modalPrompt
        .modal(this.detail.keyCustomerNo)
        .then((keyCustomerNo) => {
          updateFlightOrderKeyCustomerNo(this.id, { keyCustomerNo }, (v) =>
            this.commonShowMessage(v)
          );
        })
        .catch((ex) => {});
    },
    fillTicketNo: function () {
      this.$refs.fillTicketNoModal
        .modal(this.detail.passengers)
        .then((info) => {
          updateFlightOrderTicket(this.id, JSON.stringify(info), (v) =>
            this.commonShowMessage(v)
          );
        })
        .catch((ex) => {});
    },
    addInsurance: function () {
      this.$router.push({
        path: "/insurance/order",
        query: { flightOrderId: this.id },
      });
    },
    addExtraService: function () {
      this.$router.push({
        path: "/new/vas/order",
        query: { flightOrderId: this.id },
      });
    },
    addExtraService2: function () {
      this.$router.push({
        path: "/vaas/order",
        query: { flightOrderId: this.id },
      });
    },
    prepareDelivery: function () {
      this.$router.push({
        path: "/delivery/note",
        query: { orderNo: this.detail.orderNo },
      });
    },
    denyCancelRequest: function () {
      this.modalTitle = "请输入拒绝理由：";
      this.modalNullable = false;
      this.$refs.modalPrompt
        .modal()
        .then((remark) => {
          const params = {
            reasonDesc: remark,
            requestId: this.detail.cancelRequest.id,
          };
          denyFlightOrderCancelRequest(this.id, params, (v) =>
            this.commonShowMessage(v)
          );
        })
        .catch((ex) => {});
    },
    agreeCancelRequest: function () {
      const params = { requestId: this.detail.cancelRequest.id };
      agreeFlightOrderCancelRequest(this.id, params, (jsonResult) => {
        this.commonShowMessage(jsonResult);
      });
    },
    commonShowMessage: function (jsonResult) {
      if (jsonResult.status !== "OK") {
        this.showErrMsg("失败：" + jsonResult.errmsg, "danger");
      } else {
        if (jsonResult.desc !== "") {
          this.showErrMsg(jsonResult.desc);
        } else {
          this.showErrMsg("操作成功");
        }
        this.searchOrderDetail();
      }
    },
    sendApprovalSms: function (index) {
      this.modalTitle = "请输入接收短信的手机号（默认使用代订人号码）：";
      this.modalNullable = true;
      this.$refs.modalSms
        .modal(0, this.id, 0)
        .then((v) => {
          sendFlightOrderApprovalSms(
            this.id,
            { mobileNo: v.mobile, smsContent: v.smsContent },
            (v) => {
              this.commonShowMessage(v);
            }
          );
        })
        .catch((ex) => {});
    },
    changeTicketer: function () {
      this.modalTitle = "更改出票人";
      this.modalTitle2 = "出票人";
      this.$refs.updateOp2Modal
        .modal(this.detail.ticketer)
        .then((info) => {
          updateFlightOrderTicketer(this.id, { ticketer: info.op1 }, (v) =>
            this.commonShowMessage(v)
          );
        })
        .catch((ex) => {});
    },
    rollbackStatus: function () {
      this.modalTitle = "确定将订单状态回滚吗？并请输入理由：";

      this.$refs.modalPrompt
        .modal()
        .then((remark) => {
          rollbackFlightOrderStatus(this.id, { remark }, (v) =>
            this.commonShowMessage(v)
          );
        })
        .catch((ex) => {
          console.log(ex);
        });
    },
    payForExternalOrder: function () {
      payForExternalOrder(this.id, (v) => {
        this.commonShowMessage(v);
      });
    },
    issueTicket: function (btn) {
      $(btn).attr("disabled", true);
      issueFlightOrderTicket(
        this.id,
        (v) => {
          this.commonShowMessage(v);
        },
        () => $(btn).attr("disabled", false)
      );
    },
    cancelClaim: function (btn) {
      $(btn).attr("disabled", true);
      cancelClaimFlightOrder(
        this.id,
        (v) => {
          this.commonShowMessage(v);
        },
        () => $(btn).attr("disabled", false)
      );
    },
    printItinerary: function () {
      const url =
        "/" + APP_FLIGHT_PATH + "/order/flight/" + this.id + "/itinerary";
      window.open(url);
    },
    showOrderType: function (orderType) {
      return showOrderTypeDesc(orderType);
    },
    showVialationStatus: function (status) {
      return showViolationStatus(status);
    },
    showApprovalStatus: function (status) {
      return showApprovalStatus(status);
    },
    showTicketStatus: function (status) {
      return showTicketStatus(status);
    },
    editAttachment2: function () {
      this.$refs.modalUploadFile.modal().then((v) => {
        this.commonShowMessage(v);
      });
    },
    viewImg: function (imgUrl) {
      console.log(imgUrl);
      this.$refs.modalViewer.modal(imgUrl);
    },
    uploadPassengers: function () {
      this.$refs.modalUploadExcel
        .modal()
        .then((formData) => {
          console.log("processing....");
          this.showLoading("处理中......");
          uploadFlightOrderPassengers(
            this.id,
            formData.data,
            (v) => {
              if (v.status === "OK") {
                this.showErrMsg("操作成功");
                this.searchOrderDetail();
              } else {
                this.showErrMsg("操作失败:" + v.errmsg, "danger");
              }
            },
            () => {
              this.hideLoading();
            }
          );
        })
        .catch((ex) => {});
    },
    changeSupplierType: function (supplierType) {
      const params = { supplierType };
      changeFlightOrderSupplierType(this.id, params, (v) => {
        if (v.status === "OK") {
          this.showErrMsg("操作成功");
          this.searchOrderDetail();
        } else {
          this.showErrMsg(v.errmsg, "danger");
        }
      });
    },
    exportGroupPassengerFile: function (twoCode) {
      const url =
        "/" +
        APP_FLIGHT_PATH +
        "/order/flight/" +
        this.id +
        "/groupPassenger/" +
        twoCode;
      console.log(url);
      window.open(url);
    },
    createEotmsFlightOrder: function (btn) {
      //生成eotms机票订单
      $(btn).attr("disabled", true);
      createEotmsFlightOrder(
        this.id,
        { supplierId: this.tmsSupplierId },
        (v) => {
          this.commonShowMessage(v);
          this.searchEotmsFlightOrders();
        },
        () => {
          $(btn).attr("disabled", false);
        }
      );
    },
    syncEotmsFlightOrderStatus: function (externalOrderId, btn) {
      $(btn).attr("disabled", true);
      syncEotmsFlightOrderStatus(
        externalOrderId,
        (v) => {
          this.commonShowMessage(v);
          this.searchEotmsFlightOrders();
        },
        () => {
          $(btn).attr("disabled", false);
        }
      );
    },
    confirmEotmsFlightOrder: function (externalOrderId, btn) {
      $(btn).attr("disabled", true);
      confirmEotmsFlightOrder(
        externalOrderId,
        (v) => {
          this.commonShowMessage(v);
        },
        () => {
          $(btn).attr("disabled", false);
        }
      );
    },
    searchEotmsFlightOrders: function () {
      searchEotmsFlightOrders(this.id, (v) => {
        this.tmsExternalOrders = v;
      });
    },
    searchTmsSuppliers: function () {
      searchTmsSuppliers((v) => {
        this.tmsSuppliers.splice(0);
        for (let info of v) {
          this.tmsSuppliers.push({ id: info.id, name: info.name });
        }
      });
    },
    syncFlightOrderExternalOrderStatus: function (btn) {
      $(btn).attr("disabled", true);
      syncFlightOrderExternalOrderStatus(
        this.id,
        (v) => {
          this.commonShowMessage(v);
        },
        () => {
          $(btn).attr("disabled", false);
        }
      );
    }
  },
};
//  874
// 1859
// 2008 2021-11-09
// 1983 2021-11-10
</script>